<template>
  <div>
    <!--部门数据-->
    <div class="head-container">
      <el-input
        v-model="deptName"
        placeholder="请输入镇村名称"
        clearable
        size="small"
        prefix-icon="el-icon-search"
        style="margin-bottom: 20px"
      />
    </div>
    <div class="head-container">
      <el-tree
        :data="deptOptions"
        :props="defaultProps"
        :expand-on-click-node="false"
        :filter-node-method="filterNode"
        ref="tree"
        :default-expand-all="false"
        highlight-current
        @node-click="handleNodeClick"
      />
    </div>
  </div>
</template>

<script>
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

import { deptTdqqTreeSelect } from "./api";
export default {
  name: "deptTree",
  props: {},
  data() {
    return {
      // 部门树选项
      deptOptions: undefined,
      // 部门名称
      deptName: undefined,
      deptId: 2,
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    },
    deptId(val) {
      //this.form.deptId = val;
      //给父窗体赋值deptId//向父组件发点击节点消息
    },
  },
  created() {
    this.getDeptTree();
  },
  methods: {
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTdqqTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      // this.queryParams.deptId = data.id;
      this.deptId = data.id;
      // console.log(this.deptId);
      this.$emit("onDeptIdChanged", data);

      // this.countButtonTitle =  data.label;
      // this.handleQuery();
      // this.getTudiCountInfo();
    },
  },
};
</script>

<style scoped>
.el-tree {
  height: 100vh;
  overflow-y: scroll;
  border: 1px solid #DCDFE6;
    border-radius: 5px;
    padding: 5px 0;
}
.el-tree::-webkit-scrollbar {
  width: 0;
}
</style>
